<?php
/*
Plugin Name: XStandard
Plugin URI: http://contactsheet.de/xstandard.xhtml
Description: Integrates XStandard Editor into WordPress. XStandard is a standards-compliant, flexible and highly customizable WYSIWYG-solution. It ensures, the that your markup validates against XHTML 1.0 Strict and XHTML 1.1 specifications. Configure your WYSIWYGs on the <a href="options-general.php?page=xstandard.php">XStandard Options Page</a> (if you enable this feature, users can customize their WYSIWYG settings in their <a href="profile.php">Profile Page</a> or on a per post basis. 
Version: 0.5
Author: <a href="http://www.contactsheet.de/">Erik Pöhler</a>
Author URI: http://www.contactsheet.de/
Update Server: http://contactsheet.de/download/xstandard/
Min WP Version: 2.1
Max WP Version: 2.7.1
*/

/*__________________________________________________________________________________
 |                                                                                  |
 |   Copyright 2009  Erik Pöhler  (email : sayhello@erikpoehler.com)                |
 |                                                                                  |
 |   This program is free software; you can redistribute it and/or modify           |
 |   it under the terms of the GNU General Public License as published by           |
 |   the Free Software Foundation; either version 2 of the License, or              |
 |   (at your option) any later version.                                            |
 |                                                                                  |
 |   This program is distributed in the hope that it will be useful,                |
 |   but WITHOUT ANY WARRANTY; without even the implied warranty of                 |
 |   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                  |
 |   GNU General Public License for more details.                                   |
 |                                                                                  |
 |   You should have received a copy of the GNU General Public License              |
 |   along with this program; if not, write to the Free Software                    |
 |   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA      |
 |__________________________________________________________________________________|
*/

// don't do this at home kids
/*
error_reporting(E_ALL); 
ini_set('display_errors', 1);
*/
	if (!class_exists("XStandard")) {
		class XStandard {
			var $adminOptionsName = "XStandardAdminOptions";
			var $generalEditorOptionsName = "XStandardGeneralOptions";
			static $bitmaskOptions = array('DISABLEHARDRETURNS'
				,'AUTOFIX'
				,'NOCONTEXTMENU'
				,'WRAPINSOURCE'
				,'NOLNINSOURCE'
				,'NOOBJRESIZING'
				,'UPLOADDECO'
				,'NIY'
				,'SPACES2HARDSPACES'
				,'NOADVANCEDEDITING'
				,'SOAP12'
				,'DIVSTRUCTURE'
				,'DISABLEDIRONSELECT'
				,'DISABLEPASTEFIX'
				,'REMOVENONSTANDARD'
				,'PASTEIMGASALT'
				,'STRICTPASTE'
				,'DISPLAYCLASSFIELD'
				,'DISPLAYIDFIELD');
			static $bitmaskOptionDescs = array(
				"Display hard returns.",
				"Automatically fix errors when \"dirty\" code is loaded into the editor.",
				"Disable context menus (pop-up menus when the right mouse button is clicked).",
				"Wrap text in View Source.",
				"Hide line numbers in View Source.",
				"Disable object resizing by dragging (using image \"handles\" for example).",
				"Treat uploading images as decorative.",
				"Reserved for future use.",
				"Convert extra spaces into hard-spaces.",
				"Hide advanced editing features (Advanced and Custom tabs as well as certain fields in Properties dialog boxes).",
				"Use SOAP 1.2",
				"Treat &lt;div> as as structure element. By default, &lt;div> is used as a grouping element.",
				"Disable Directory button when content is selected.",
				"Disable \"Fix\" option when invalid markup is entered into View Source and user switches to WYSIWYG view.",
				"Automatically remove undefined custom elements. To define custom elements, use CustomInlineElements and CustomBlockElements properties.",
				"Paste images as alternate text when file upload is unavailable/disabled.",
				"Strict mode when pasting from applications like Word. Removes attributes like id, align and valign.",
				"Display the \"Class\" field on the General tab of the Properties dialog box in the simplified interface (when Options 512 is set). The only exception to this is in the Image properties dialog box when there is a value in ClassImageFloatLeft / ClassImageFloatRight properties.",
				"Display the \"ID\" field on the General tab of the Properties dialog box in the simplified interface (when Options 512 is set).");
			var $main;

			function init() {
				$this->getAdminOptions();
				$this->getXStandardOptions();
			}


			public function XStandard() {
				update_user_option( $user->ID, 'mfold', 'o' );
				require_once realpath(dirname(__FILE__) . '/lib/XStandardConstants.script.php');
				$this->readVersionInformation();
				// I18N support through GNU-Gettext files
				load_plugin_textdomain('xs', 'wp-content/plugins/' . XS_PLUGINDIR_NAME . '/lib/l10n/');
				require_once($_SERVER['DOCUMENT_ROOT']."/wp-content/plugins/xstandard/lib/php/bitmask.class.php");
				$this->main = new bitmask;
			}


			public function readVersionInformation() {
				// Get the readme.txt file contents
				$readmeContent = file_get_contents(realpath(dirname(__FILE__) . '/readme.txt'));
				
				// Since we don't want to execute regular expressions against the whole file, we extract the header part
				$readmeHeader = substr($readmeContent, 0, strpos($readmeContent, '== Description =='));
				
				// Extract the defined version numbers
				$this->pluginVersion = $this->_parseReadmeValue($readmeHeader, 'Stable tag');
				$this->requiredWordPressVersion = $this->_parseReadmeValue($readmeHeader, 'Requires at least');
				$this->highestTestedWordPressVersion = $this->_parseReadmeValue($readmeHeader, 'Tested up to');
				$this->xstandardVersionIncluded = $this->_parseReadmeValue($readmeHeader, 'XStandard Version included');
				$this->xstandardLatest = $this->_getVersionFile("http://www.contactsheet.de/xstandard.txt", &$error, $timeout=10, $followredirects=true);
			}


			/** 
			 * Function extracts a value from the readme header
			 *
			 * @param string $readmeHeader
			 * @param string $key
			 * @return string
			 **/
			public function _parseReadmeValue($readmeHeader, $key) {
				preg_match('#' . $key . '\s*:\s*([0-9.]+)#i', $readmeHeader, $match);
				return $match[1];
			}


			public function URLreadFsock($host, $file, &$errstr, $successonly=true, $port=80, $timeout=10) {
				if (!function_exists('fsockopen')) {
					$errstr = 'fsockopen() unavailable';
					return false;
				}
				if ($fp = @fsockopen($host, 80, $errno, $errstr, $timeout)) {
					$out  = 'GET '.$file.' HTTP/1.0'."\r\n";
					$out .= 'Host: '.$host."\r\n";
					$out .= 'Connection: Close'."\r\n\r\n";
					fwrite($fp, $out);
		
					$isHeader = true;
					$Data_header = '';
					$Data_body   = '';
					$header_newlocation = '';
					while (!feof($fp)) {
						$line = fgets($fp, 1024);
						if ($isHeader) {
							$Data_header .= $line;
						} else {
							$Data_body .= $line;
						}
						if (eregi('^HTTP/[\\.0-9]+ ([0-9]+) (.+)$', rtrim($line), $matches)) {
							list($dummy, $errno, $errstr) = $matches;
							$errno = intval($errno);
						} elseif (eregi('^Location: (.*)$', rtrim($line), $matches)) {
							$header_newlocation = $matches[1];
						}
						if ($isHeader && ($line == "\r\n")) {
							$isHeader = false;
							if ($successonly) {
								switch ($errno) {
									case 200:
										// great, continue
										break;
		
									default:
										$errstr = $errno.' '.$errstr.($header_newlocation ? '; Location: '.$header_newlocation : '');
										fclose($fp);
										return false;
										break;
								}
							}
						}
					}
					fclose($fp);
					return $Data_body;
				}
				return null;
			}


			public function ParseURLbetter($url) {
				$parsedURL = @parse_url($url);
				if (!@$parsedURL['port']) {
					switch (strtolower(@$parsedURL['scheme'])) {
						case 'ftp':
							$parsedURL['port'] = 21;
							break;
						case 'https':
							$parsedURL['port'] = 443;
							break;
						case 'http':
							$parsedURL['port'] = 80;
							break;
					}
				}
				return $parsedURL;
			}

			// fetch the latest version of XStandard
			public function _getVersionFile($url, &$error, $timeout=10, $followredirects=true) {
				$error = '';
		
				$parsed_url = XStandard::ParseURLbetter($url);
				$alreadyLookedAtURLs[trim($url)] = true;
				
				while (true) {
					$tryagain = false;
					$rawData = $this->URLreadFsock(@$parsed_url['host'], @$parsed_url['path'].'?'.@$parsed_url['query'], $errstr, true, (@$parsed_url['port'] ? @$parsed_url['port'] : 80), $timeout);
					if (eregi('302 [a-z ]+; Location\\: (http.*)', $errstr, $matches)) {
						$matches[1] = trim(@$matches[1]);
						if (!@$alreadyLookedAtURLs[$matches[1]]) {
							// loop through and examine new URL
							$error .= 'URL "'.$url.'" redirected to "'.$matches[1].'"';
		
							$tryagain = true;
							$alreadyLookedAtURLs[$matches[1]] = true;
							$parsed_url = $this->ParseURLbetter($matches[1]);
						}
					}
					if (!$tryagain) {
						break;
					}
				}
				
				if ($rawData === false) {
					$error .= 'Error opening "'.$url.'":'."\n\n".$errstr;
					return false;
				} elseif ($rawData === null) {
					// fall through
					$error .= 'Error opening "'.$url.'":'."\n\n".$errstr;
				} else {
					return trim($rawData);
				}
				
				// curl
				if (function_exists('curl_version')) {
					$ch = curl_init();
					curl_setopt($ch, CURLOPT_URL, $url);
					curl_setopt($ch, CURLOPT_HEADER, false);
					curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
					curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
					curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
					$rawData = curl_exec($ch);
					curl_close($ch);
					if (strlen($rawData) > 0) {
						$error .= 'CURL succeeded ('.strlen($rawData).' bytes); ';
						return trim($rawData);
					}
					$error .= 'CURL available but returned no data; ';
				} else {
					$error .= 'CURL unavailable; ';
				}
				
				// fopen
				$BrokenURLfopenPHPversions = array('4.4.2');
				if (in_array(phpversion(), $BrokenURLfopenPHPversions)) {
					$error .= 'fopen(URL) broken in PHP v'.phpversion().'; ';
				} elseif (@ini_get('allow_url_fopen')) {
					$rawData = '';
					$error_fopen = '';
					ob_start();
					if ($fp = fopen($url, 'rb')) {
						do {
							$buffer = fread($fp, 8192);
							$rawData .= $buffer;
						} while (strlen($buffer) > 0);
						fclose($fp);
					} else {
						$error_fopen .= trim(strip_tags(ob_get_contents()));
					}
					ob_end_clean();
					$error .= $error_fopen;
					if (!$error_fopen) {
						$error .= '; "allow_url_fopen" succeeded ('.strlen($rawData).' bytes); ';
						return trim($rawData);
					}
					$error .= '; "allow_url_fopen" enabled but returned no data ('.$error_fopen.'); ';
				} else {
					$error .= '"allow_url_fopen" disabled; ';
				}
				return false;
			}


			// General XStandard Editor Settings
			private function getXStandardOptions() {
				// initial default settings
				$xsGeneralEditorOptions = array(
					"EditorDefaultHeight"	=>		"420"
					,"BackgroundColor"		=> 		"#FFFFFF"
					,"BorderColor"			=> 		"#CCCCCC"
					,"Buttons"				=> 		"" // used to change icons and define buttons for the toolbar eg: XS_URL."lib/xml/default_buttons.xml" 
					,"ClassImageFloatLeft"	=> 		"align_left"
					,"ClassImageFloatRight"	=> 		"align_right"
					,"CSS" 					=> 		XS_URL."lib/css/default.css" // can be the same CSS file used on your Web site
					,"CustomInlineElements"	=> 		"" // comma separated list
					,"CustomBlockElements"	=> 		"" // comma separated list
					,"CustomEmptyElements"	=> 		"more" // as XStandard doesn't support HTML comments. We use a custom element which we can str_replace on submit
					,"Debug"				=> 		"no" // provide an option to analyze possible problems 
					,"EditorCSS" 			=> 		XS_URL."lib/css/default_wysiwyg.css" 			// wysiwyg only css rules
					,"EnableCache" 			=> 		"true" // TODO: add lastmod filestamp to affected values - affects CSS EditorCSS Styles Localization ScreenReaderXSLT PreviewXSLT Buttons Icons  Placeholders License
					,"EnableTimestamp"		=> 		"false" // want an XStandard comment in each posts source code?
					,"EnablePasteMarkup"	=> 		"true" // enable/disable copy/paste
					,"EscapeUnicode"		=>		"false" // true = escape non ascii chars (only needed for non UTF-8 CMS)
					,"ExpandWidth" 			=> 		"100%" // fullscreen mode or something?!
					,"ExpandHeight"			=>		"100%"
					,"ExpandToolbarWysiwyg"	=>		""
					,"ExpandToolbarSource"	=>		""
					,"ExpandToolbarPreview"	=>		""
					,"ExpandToolbarScreenReader"=>	""
					,"ExpandShowStyles" 	=> 		"true"
					,"ExpandShowToolbar"	=>		"true"
					,"HeartbeatURL"			=>		"" // TODO: probably not needed since wp doesn't use sessions and has its own autosave feature/interval
					,"HeartbeatInterval"	=>		300
					,"Icons"				=>		XS_URL."lib/xml/default_icons.xml"
					,"IndentOutput"			=>		"yes"
					,"Lang"					=>		XS_LANG
					,"LatestVersion"		=>		$this->xstandardLatest
					,"License"				=>		"" // WordPress users don't have licenses :D
					,"Localization"			=>		XS_URL."lib/xml/l10n-".XS_LANG.".xml"
					,"Mode"					=>		"wysiwyg" // default mode
					,"Namespaces"			=>		""
					,"Options"				=>		2048
					,"Placeholders"			=>		XS_URL."lib/xml/default_placeholders.xml"
					,"PreviewXSLT"			=>		XS_URL."lib/xsl/default_preview.xsl"
					,"Rel"					=>		"me, contact, acquaintance, friend, met, co-worker, colleague, co-resident, neighbor, child, kin, parent, sibling, spouse, muse, crush, date, sweetheart"
					,"Rev"					=>		"me, contact, acquaintance, friend, met, co-worker, colleague, co-resident, neighbor, child, kin, parent, sibling, spouse, muse, crush, date, sweetheart"
					,"ScreenReaderXSLT"		=>		XS_URL."lib/xsl/default_screenreader.xsl"
					,"Styles"				=>		XS_URL."lib/xml/default_styles.xml" // IMPORTANT Markup information
					,"ShowStyles"			=> 		"true"
					,"ShowToolbar"			=>		"true"
					,"Toolbar"				=>		"button1, button2" // TODO: ajaxify this
					,"ToolbarWysiwyg"		=>		"button1, button2" // TODO: ajaxify this
					,"ToolbarSource"		=>		"button1, button2" // TODO: ajaxify this
					,"ToolbarPreview"		=>		"button1, button2" // TODO: ajaxify this
					,"ToolbarScreenReader "	=>		"button1, button2" // TODO: ajaxify this
					,"ToolbarEffect"		=>		"linear-gradient"
					,"Version"				=>		$this->xstandardVersionIncluded // actually I'm just guessing here... and why the heck do i save this to the DB?
// Do I understand the following settings?
// Guess there's no real use in a browser-only environment, right?
// ...maybe implement (on request) in future versions.
//					,"DocumentID"			=> 		"" // additional HTTP header --- submits a header which is available on all requests for example in PHP via $_SERVER["HTTP_X_DOCUMENT_ID"]
//					,"UserID"				=> 		"" // additional HTTP header
//					,"SessionID"			=> 		"" // additional HTTP header
//					,"TransactionID"		=> 		"" // additional HTTP header
//					,"ClientID"				=> 		"" // additional HTTP header
//					,"InstanceID"			=> 		"" // additional HTTP header
//					,"TagID"				=> 		"" // additional HTTP header
//					,"ZoneID"				=> 		"" // additional HTTP header
//					,"ProjectID"			=> 		"" // additional HTTP header
//					,"AreaID"				=> 		"" // additional HTTP header
//					,"GroupID"				=> 		"" // additional HTTP header
//					,"ParentID"				=> 		"" // additional HTTP header
//					,"ContainerID"			=> 		"" // additional HTTP header
//					,"ObjectID"				=> 		"" // additional HTTP header
					,"CMSImageLibraryURL"	=> 		XS_URL."lib/php/cmsimagelibrary.php"
					,"ImageLibraryURL"		=> 		""
					,"CMSAttachmentLibraryURL" =>	XS_URL."lib/php/cmsattachmentlibrary.php"
					,"AttachmentLibraryURL" =>		"" // XS_URL."lib/php/attachmentlibrary.php"
					,"SpellCheckerURL"		=> 		"" //XS_URL."lib/php/spellchecker.php"
					,"SpellCheckerLangFilter" =>	"" // sub-set of the dictionaries eg: en-ca, fr
					,"SpellCheckerLang"		=>		"en-us"
					,"CMSDirectoryURL"		=>		XS_URL."lib/php/cmsdirectory.php"
					,"DirectoryURL"			=>		"" // XS_URL."lib/php/directory.php"
					,"SubdocumentURL"		=>		"" // XS_URL."lib/php/subdocument.php"
					,"ProxySetting"			=>		"auto-detect"
					,"ProxyServer"			=>		""
					,"ProxyPort"			=>		""
					,"ProxyUser"			=>		""
					,"ProxyPassword"		=>		""
					
				);
				$_xsGeneralEditorOptions = get_option($this->generalEditorOptionsName);
				/* reset to defaults or check if already set? /
				if (!empty($_xsGeneralEditorOptions)) {
					foreach ($_xsGeneralEditorOptions as $key => $option)
						$xsGeneralEditorOptions[$key] = $option;
				}
				/**/
				update_option($this->generalEditorOptionsName, $xsGeneralEditorOptions);
				return $xsGeneralEditorOptions;
			}


			// Returns an array of admin options
			private function getAdminOptions() {
				$xsAdminOptions = array('show_header' => 'true',
										'add_content' => 'true',
										'comment_author' => 'true',
										'content' => '');
				$_xsAdminOptions = get_option($this->adminOptionsName);
				/*/
				if (!empty($_xsAdminOptions)) {
					foreach ($_xsAdminOptions as $key => $option) {
						$xsAdminOptions[$key] = $option;
					}
				}
				/**/
				update_option($this->adminOptionsName, $xsAdminOptions);
				return $xsAdminOptions;
			}


			// add JS to admin head
			function _filter_js_admin_head () { ?>
<script type="text/javascript">
/* <![CDATA[ */
(function($) {
	function fakeMissingHook() {
		var the_editor = $('#insert_xstandard').html();
		$('#titlediv').after(the_editor);
		$('#insert_xstandard').remove();
		$('#postdivrich').remove();
		$('#postdiv').css("opacity",".6");
		
		$("#post").submit(function(){
			var xs_content = document.getElementById('editor1').value;
			$("#content").text(xs_content); // update content of the textarea
			// $("#editor1").attr({name:"content",id:"content"});
			return true;
		});
		
	}
	fakeMissingHook();	
})(jQuery);
/* ]]> */
</script>

<script type="text/javascript">
<?php // TODO: jqueryfy this and replace redirection with a friendly notification or something
?>
//<![CDATA[
(function($) {
	function updateXStandard() {
		var latestVersion = '<?php print $this->xstandardLatest?>';
		if (navigator.userAgent.toLowerCase().indexOf('firefox') != -1) {
			var objects = document.getElementsByTagName('object');
			for (var i=0; i<objects.length; i++) {
				var obj = objects[i];
				try {
					if(typeof(obj.EscapeUnicode) == 'undefined') {
						throw "Error"
					} else {
						if (obj.Version != latestVersion) {
							window.location.replace('http://xstandard.com/upgrade-firefox-version/');
							break;
						}
					}
				}
				catch(er) {}
			}
		}
	}
	updateXStandard();	
})(jQuery);
//]]>
</script>
<!--[if !IE]>-->
	<!--script type="text/javascript" src="<?=XS_URL?>lib/js/xstandard.js"></script-->
<!--<![endif]-->
			<?php
			}

			function _filter_edit_form_advanced() {
				$opt = $this -> getXStandardOptions();
				//	Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\dev\wp-content\plugins\xstandard\xstandard.php on line 370
				print '<div id="debug">';
				if (isset($_GET['post'])) {
					$postid = $_GET['post'];
					$post = &get_post($postid);
				}
				print_r($post);
				$the_editor = "</div>";
				$the_editor .= '<div id="insert_xstandard">'."\n";
				if (strlen($opt["EditorDefaultHeight"]) && is_int($opt["EditorDefaultHeight"])) { $editor_height = $opt["EditorDefaultHeight"]; } else { $editor_height = 420; }
				$the_editor .= '<object type="application/x-xstandard" name="editor1" id="editor1" width="100%" height="'.$editor_height.'" style="margin:-20px 0 15px 0;">'."\n";
				// TODO: clsid for the sake of IE7+ auto installation. classid="clsid:0EED7206-1661-11D7-84A3-00606744831D"
				
				// REMEMBER: not echoing parameters will have XStandard use its internal default. Make sure that's wanted in all cases.
				
				if(strlen($opt["BackgroundColor"])) {
					$the_editor .= '	<param name="BackgroundColor" value="'.$opt["BackgroundColor"].'" />'."\n";
				}
				if(strlen($opt["BorderColor"])) {
					$the_editor .= '	<param name="BorderColor" value="'.$opt["BorderColor"].'" />'."\n";
				}
				$the_editor .= '	<param name="Base" value="'.trailingslashit(get_bloginfo("url")).'" />'."\n";
				
				if(strlen($opt["Buttons"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["Buttons"]))) {
					$the_editor .= '	<param name="Buttons" value="'.wp_make_link_relative($opt["Buttons"]).'" />'."\n";
				}
				if(strlen($opt["ClassImageFloatLeft"])) {
					$the_editor .= '	<param name="ClassImageFloatLeft" value="'.$opt["ClassImageFloatLeft"].'" />'."\n";
				}
				if(strlen($opt["ClassImageFloatRight"])) {
					$the_editor .= '	<param name="ClassImageFloatRight" value="'.$opt["ClassImageFloatRight"].'" />'."\n";
				}
				if(!strlen($opt["License"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["License"]))) {
				/* no need for this if a license file is present.
				 * (this effectively turns XStandard Lite into XStandard half pro OSCMS mode)
				 * note: Who the fuck is Joomla? Come on Belus! Don't piss off the WordPress community! 
				 */
					$the_editor .= '	<param name="CMSCode" value="065126D6-357D-46FC-AF74-A1F5B2D5036E" />'."\n";
				}
				// $the_editor .= '	<param name="Cookie" value="" />'."\n";
				if(strlen($opt["CSS"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["CSS"]))) {
					$the_editor .= '	<param name="CSS" value="'.wp_make_link_relative($opt["CSS"]).'" />'."\n";
				}
				if(strlen($opt["CustomInlineElements"])) {
					$the_editor .= '	<param name="CustomInlineElements" value="'.$opt["CustomInlineElements"].'" />'."\n";
				}
				if(strlen($opt["CustomBlockElements"])) {
					$the_editor .= '	<param name="CustomBlockElements" value="'.$opt["CustomBlockElements"].'" />'."\n";
				}
				if(strlen($opt["CustomEmptyElements"])) {
					$the_editor .= '	<param name="CustomEmptyElements" value="'.$opt["CustomEmptyElements"].'" />'."\n";
				}
				if(strlen($opt["Debug"])) {
					$the_editor .= '	<param name="Debug" value="'.$opt["Debug"].'" />'."\n";
				}
				$the_editor .= '	<param name="Dir" value="'.get_bloginfo('text_direction').'" />'."\n";
				if(strlen($opt["EditorCSS"])) {
					$the_editor .= '	<param name="EditorCSS" value="'.$opt["EditorCSS"].'" />'."\n";
				}
				if(strlen($opt["EnableCache"])) {
					$the_editor .= '	<param name="EnableCache" value="'.$opt["EnableCache"].'" />'."\n";
				}
				if(strlen($opt["EnablePasteMarkup"])) {
					$the_editor .= '	<param name="EnablePasteMarkup" value="'.$opt["EnablePasteMarkup"].'" />'."\n";
				}
				if(strlen($opt["EnableTimestamp"])) {
					$the_editor .= '	<param name="EnableTimestamp" value="'.$opt["EnableTimestamp"].'" />'."\n";
				}
				if(strlen($opt["EscapeUnicode"])) {
					$the_editor .= '	<param name="EscapeUnicode" value="'.$opt["EscapeUnicode"].'" />'."\n";
				}
				if(strlen($opt["ExpandWidth"])) {
					$the_editor .= '	<param name="ExpandWidth" value="'.$opt["ExpandWidth"].'" />'."\n";
				}
				if(strlen($opt["ExpandHeight"])) {
					$the_editor .= '	<param name="ExpandHeight" value="'.$opt["ExpandHeight"].'" />'."\n";
				}
				if(strlen($opt["ExpandToolbarWysiwyg"])) {
					$the_editor .= '	<param name="ExpandToolbarWysiwyg" value="'.$opt["ExpandToolbarWysiwyg"].'" />'."\n";
				}
				if(strlen($opt["ExpandToolbarSource"])) {
					$the_editor .= '	<param name="ExpandToolbarSource" value="'.$opt["ExpandToolbarSource"].'" />'."\n";
				}
				if(strlen($opt["ExpandToolbarPreview"])) {
					$the_editor .= '	<param name="ExpandToolbarPreview" value="'.$opt["ExpandToolbarPreview"].'" />'."\n";
				}
				if(strlen($opt["ExpandToolbarScreenReader"])) {
					$the_editor .= '	<param name="ExpandToolbarScreenReader" value="'.$opt["ExpandToolbarScreenReader"].'" />'."\n";
				}
				if(strlen($opt["ExpandShowStyles"])) {
					$the_editor .= '	<param name="ExpandShowStyles" value="'.$opt["ExpandShowStyles"].'" />'."\n";
				}
				if(strlen($opt["ExpandShowToolbar"])) {
					$the_editor .= '	<param name="ExpandShowToolbar" value="'.$opt["ExpandShowToolbar"].'" />'."\n";
				}
				if(strlen($opt["HeartbeatURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["HeartbeatURL"]))) {
					$the_editor .= '	<param name="HeartbeatURL" value="'.$opt["HeartbeatURL"].'" />'."\n";
					if(strlen($opt["HeartbeatInterval"])) {
						$the_editor .= '	<param name="HeartbeatInterval" value="'.$opt["HeartbeatInterval"].'" />'."\n";
					}
				}
				if(strlen($opt["Icons"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["Icons"]))) {
					$the_editor .= '	<param name="Icons" value="'.wp_make_link_relative($opt["Icons"]).'" />'."\n";
				}
				if(strlen($opt["IndentOutput"])) {
					$the_editor .= '	<param name="IndentOutput" value="'.$opt["IndentOutput"].'" />'."\n";
				}
				$the_editor .= '	<param name="Lang" value="'.XS_LANG.'" />'."\n";
				$the_editor .= '	<param name="LatestVersion" value="'.$this->xstandardLatest.'" />'."\n";
				if(strlen($opt["License"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["License"]))) {
					$the_editor .= '	<param name="License" value="'.$opt["License"].'" />'."\n";
				}
				// TODO: use file based localization as override option. Better: l10n via .pot/.mo
				if(strlen($opt["Localization"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["Localization"]))) {
					$the_editor .= '	<param name="Localization" value="'.wp_make_link_relative($opt["Localization"]).'" />'."\n";
				}
				if(is_array($opt["Mode"])&&count($opt["Mode"])>0) {
					$the_editor .= '	<param name="Mode" value="'.$opt["Mode"].'" />'."\n";
				}
				if(strlen($opt["Namespaces"])) {
					$the_editor .= '	<param name="Namespaces" value="'.$opt["Namespaces"].'" />'."\n"; // syntax example: xmlns:a='http://apple-books' xmlns:b='http://big-books'
				}
				if(strlen($opt["Options"]) && is_int($opt["Options"])) {
					$the_editor .= '	<param name="Options" value="'.$opt["Options"].'" />'."\n";
				}
				if(strlen($opt["Placeholders"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["Placeholders"]))) {
					$the_editor .= '	<param name="Placeholders" value="'.wp_make_link_relative($opt["Placeholders"]).'" />'."\n";
				}
				if(strlen($opt["PreviewXSLT"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["PreviewXSLT"]))) {
					$the_editor .= '	<param name="PreviewXSLT" value="'.wp_make_link_relative($opt["PreviewXSLT"]).'" />'."\n";
				}
				if(strlen($opt["Rel"])) {
					$the_editor .= '	<param name="Rel" value="'.$opt["Rel"].'" />'."\n";
				}
				if(strlen($opt["Rev"])) {
					$the_editor .= '	<param name="Rev" value="'.$opt["Rev"].'" />'."\n";
				}
				if(strlen($opt["ScreenReaderXSLT"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["ScreenReaderXSLT"]))) {
					$the_editor .= '	<param name="ScreenReaderXSLT" value="'.wp_make_link_relative($opt["ScreenReaderXSLT"]).'" />'."\n";
				}
				// $the_editor .= '	<param name="ScriptNewWindow" value="" />'."\n"; bad. use a class and unobstrusive js to solve shortcomings here
				if(strlen($opt["Styles"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["Styles"]))) {
					$the_editor .= '	<param name="Styles" value="'.wp_make_link_relative($opt["Styles"]).'" />'."\n";
				}
				$the_editor .= '	<param name="ShowStyles" value="'.$opt["ShowStyles"].'" />'."\n";
				$the_editor .= '	<param name="ShowToolbar" value="'.$opt["ShowToolbar"].'" />'."\n";
/* make available in admin cp first
				$the_editor .= '	<param name="Toolbar" value="'.$opt["Toolbar"].'" />'."\n";
				$the_editor .= '	<param name="ToolbarWysiwyg" value="'.$opt["ToolbarWysiwyg"].'" />'."\n";
				$the_editor .= '	<param name="ToolbarSource" value="'.$opt["ToolbarSource"].'" />'."\n";
				$the_editor .= '	<param name="ToolbarPreview" value="'.$opt["ToolbarPreview"].'" />'."\n";
				$the_editor .= '	<param name="ToolbarScreenReader" value="'.$opt["ToolbarScreenReader"].'" />'."\n";
*/
				if(strlen($opt["ToolbarEffect"])) { // a fancy gradient? tsss
					$the_editor .= '	<param name="ToolbarEffect" value="'.$opt["ToolbarEffect"].'" />'."\n";
				}
				/* trying to get the posts content */
				$xs_content = htmlspecialchars($post->post_content);
				if (strlen($xs_content)<1) {
					$xs_content = $post->post_content_filtered;
					if (strlen($xs_content)<1) {
						die("kein inhalt in content - keiner in content_filtered - was nun?");
					}
				}
				$the_editor .= '	<param name="Value" value="'.$xs_content.'" />'."\n";
				if(strlen($opt["Version"])) {
					$the_editor .= '	<param name="Version" value="'.$opt["Version"].'" />'."\n";
				}
// print_r($post);
				/** not implemented yet: sending additional http headers 
				 * submits a header which is available on all requests e.g. via php with $_SERVER["HTTP_X_DOCUMENT_ID"]
				 */

/**				if(strlen($opt["DocumentID"])) {
					$the_editor .= '	<param name="DocumentID" value="" />'."\n";
				}
				if(strlen($opt["UserID"])) {
					$the_editor .= '	<param name="UserID" value="" />'."\n";
				}
				if(strlen($opt["SessionID"])) {
					$the_editor .= '	<param name="SessionID" value="" />'."\n";
				}
				if(strlen($opt["TransactionID"])) {
					$the_editor .= '	<param name="TransactionID" value="" />'."\n";
				}
				if(strlen($opt["ClientID"])) {
					$the_editor .= '	<param name="ClientID" value="" />'."\n";
				}
				if(strlen($opt["InstanceID"])) {
					$the_editor .= '	<param name="InstanceID" value="" />'."\n";
				}
				if(strlen($opt["TagID"])) {
					$the_editor .= '	<param name="TagID" value="" />'."\n";
				}
				if(strlen($opt["ZoneID"])) {
					$the_editor .= '	<param name="ZoneID" value="" />'."\n";
				}
				if(strlen($opt["ProjectID"])) {
					$the_editor .= '	<param name="ProjectID" value="" />'."\n";
				}
				if(strlen($opt["AreaID"])) {
					$the_editor .= '	<param name="AreaID" value="" />'."\n";
				}
				if(strlen($opt["GroupID"])) {
					$the_editor .= '	<param name="GroupID" value="" />'."\n";
				}
				if(strlen($opt["ParentID"])) {
					$the_editor .= '	<param name="ParentID" value="" />'."\n";
				}
				if(strlen($opt["ContainerID"])) {
					$the_editor .= '	<param name="ContainerID" value="" />'."\n";
				}
				if(strlen($opt["ObjectID"])) {
					$the_editor .= '	<param name="ObjectID" value="" />'."\n";
				}
				/** end additional http header **/

				/** start server-side applications **/ 
				// pro
				if(strlen($opt["ImageLibraryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["ImageLibraryURL"]))) {
					$the_editor .= '	<param name="ImageLibraryURL" value="'.$opt["ImageLibraryURL"].'" />'."\n";
				}
				// oscms
				if(strlen($opt["CMSImageLibraryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["CMSImageLibraryURL"]))) {
					$the_editor .= '	<param name="CMSImageLibraryURL" value="'.$opt["CMSImageLibraryURL"].'" />'."\n";
				}
				// pro
				if(strlen($opt["AttachmentLibraryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["AttachmentLibraryURL"]))) {
					$the_editor .= '	<param name="AttachmentLibraryURL" value="'.$opt["AttachmentLibraryURL"].'" />'."\n";
				}
				// oscms
				if(strlen($opt["CMSAttachmentLibraryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["CMSAttachmentLibraryURL"]))) {
					$the_editor .= '	<param name="CMSAttachmentLibraryURL" value="'.$opt["CMSAttachmentLibraryURL"].'" />'."\n";
				}
				if(strlen($opt["SpellCheckerURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["SpellCheckerURL"]))) {
					$the_editor .= '	<param name="SpellCheckerURL" value="'.$opt["SpellCheckerURL"].'" />'."\n";
					if(strlen($opt["SpellCheckerLangFilter"])) {
						$the_editor .= '	<param name="SpellCheckerLangFilter" value="'.$opt["SpellCheckerLangFilter"].'" />'."\n";
					}
					if(strlen($opt["SpellCheckerLang"])) {
						$the_editor .= '	<param name="SpellCheckerLang" value="'.$opt["SpellCheckerLang"].'" />'."\n";
					}
				}
				// pro
				if(strlen($opt["DirectoryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["DirectoryURL"]))) {
					$the_editor .= '	<param name="DirectoryURL" value="'.$opt["DirectoryURL"].'" />'."\n";
				}
				// oscms
				if(strlen($opt["CMSDirectoryURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["CMSDirectoryURL"]))) {
					$the_editor .= '	<param name="CMSDirectoryURL" value="'.$opt["CMSDirectoryURL"].'" />'."\n";
				}
				if(strlen($opt["SubdocumentURL"]) && file_exists($_SERVER['DOCUMENT_ROOT'].wp_make_link_relative($opt["SubdocumentURL"]))) {
					$the_editor .= '	<param name="SubdocumentURL" value="'.$opt["SubdocumentURL"].'" />'."\n";
				}
				/** end server-side applications **/
				
				/** start proxy settings **/
				if(strlen($opt["ProxySetting"])) {
					$the_editor .= '	<param name="ProxySetting" value="'.$opt["ProxySetting"].'" />'."\n";
				}
				if($opt["ProxySetting"] === 'manual') {
					if(strlen($opt["ProxyServer"])) {
						$the_editor .= '	<param name="ProxyServer" value="'.$opt["ProxyServer"].'" />'."\n";
					}
					if(strlen($opt["ProxyPort"])) {
						$the_editor .= '	<param name="ProxyPort" value="'.$opt["ProxyPort"].'" />'."\n";
					}
					if(strlen($opt["ProxyUser"])) {
						$the_editor .= '	<param name="ProxyUser" value="'.$opt["ProxyUser"].'" />'."\n";
					}
					if(strlen($opt["ProxyPassword"])) {
						$the_editor .= '	<param name="ProxyPassword" value="'.$opt["ProxyPassword"].'" />'."\n";
					}
				}
				/** end proxy settings **/
				
				// $the_editor .= '	<textarea name="content" rows="5" cols="50">'.$post->post_content.'</textarea>';
				$the_editor .= '	<span>If you do not see the editor here, you have not yet installed XStandard to your computer. Before proceeding, please download XStandard from <a href="http://xstandard.com">http://xstandard.com</a></span>';
				$the_editor .= '</object>';
				$the_editor .= '</div>';
				print $the_editor;
			}
			
			// Options Page
			function xsOptionsPage() {

				// first we handle submitted POST vars

				// 1. General Plugin and Admin Options

				$_xsAdminOptions = $this->getAdminOptions();
				if (isset($_POST['update_adminSettings'])) {
					if (isset($_POST['xsHeader'])) {
						$_xsAdminOptions['show_header'] = $_POST['xsHeader'];
					}
					if (isset($_POST['xsAddContent'])) {
						$_xsAdminOptions['add_content'] = $_POST['xsAddContent'];
					}
					if (isset($_POST['xsAuthor'])) {
						$_xsAdminOptions['comment_author'] = $_POST['xsAuthor'];
					}
					if (isset($_POST['xsContent'])) {
						$_xsAdminOptions['content'] = apply_filters('content_save_pre', $_POST['xsContent']);
				 		}
						update_option($this->adminOptionsName, $_xsAdminOptions);
?>
					<div class="updated">
						<p>
							<strong><?=__("Your general rich editing options have been updated.", 'xs');?></strong>
						</p>
					</div>
<?php 			}

				// 2. XStandard Customizations

				$_xsOptions = $this->getXStandardOptions();
				if (isset($_POST['update_xsSettings'])) {
					if (isset($_POST['BackgroundColor'])) {
						$_xsOptions['BackgroundColor'] = $_POST['BackgroundColor'];
					}
					if (isset($_POST['BorderColor'])) {
						$_xsOptions['BorderColor'] = $_POST['BorderColor'];
					}
					if (isset($_POST['Buttons'])) {
						$_xsOptions['Buttons'] = $_POST['Buttons'];
					}
					if (isset($_POST['xsContent'])) {
						$_xsOptions['content'] = apply_filters('content_save_pre', $_POST['xsContent']);
				 		}
						update_option($this->adminOptionsName, $_xsOptions);
?>
					<div class="updated">
						<p>
							<strong><?=__("Your XStandard configuration has been updated.", 'xs')?></strong>
						</p>
					</div>
<?php } ?>


				<style type="text/css">div.xs label {display:block;}</style>
				<div class="wrap xs">
					<div id="icon-options-general" class="icon32"><br /></div> 
						<h2 style="margin-top:-5px;"><img src="<?=XS_URL?>lib/l10n/logo-xstandard-<?=XS_LANG?>.gif" alt="<?=_e("XStandard for WordPress",'xs');?>" /></h2>
						<h3>General Rich Editing Options</h3>
						<form method="post" action="<?=$_SERVER["REQUEST_URI"]?>">
							<?php print get_bloginfo('text_direction'); ?>
							<ol>
								<li>Allow users to switch their editor? yes|no</li>
								<li>Allow users to customize XStandard? yes|no</li>
								<li>Define a default editor for newly registered users. Which one?</li>
								<li>other options? (fewer is better)</li>
							</ol>
							<input type="hidden" name="update_adminSettings" value="bla" />
							<input class="button-primary" type="submit" name="update_adminSettings" value="<?=__("Save Rich Editing Options","xs")?>" />
							<input class="button" type="submit" name="restore_adminSettings" value="<?=__("Restore Defaults","xs")?>" />
						</form>
						
						</form method="post" action="<?=$_SERVER["REQUEST_URI"]?>">
							<h3>Customize XStandard</h3>
							<p>When customizing XStandard, please keep in mind that all changes made to the options
							 below will affect all of your users (that have editing privileges).<br />
							<small>(although I might add support for user/role/rights management at a later time. If your missing this feature, please report back)</small></p>
							<p>Below you can change the appearance and behaviour of XStandard.</p>
							<ol>
								<li>
									<label for="EditorDefaultHeight"><?=__("Default height in px","xs")?></label>
									<input id="EditorDefaultHeight" name="EditorDefaultHeight" type="text" maxlength="4" value="<?=$_xsOptions['EditorDefaultHeight']?>" />
								</li>
								<li>
									<label for="BackgroundColor"><?=__("background color","xs")?></label>
									<input id="BackgroundColor" name="BackgroundColor" type="text" maxlength="100" value="<?=$_xsOptions['BackgroundColor']?>" />
								</li>
								<li>
									<label for="BorderColor"><?=__("BorderColor","xs")?></label>
									<input id="BorderColor" name="BorderColor" type="text" maxlength="100" value="<?=$_xsOptions['BorderColor']?>" />
								</li>
								<li>
									<label for="Buttons"><?=__("Buttons","xs")?></label>
									<input id="Buttons" name="Buttons" type="text" maxlength="" value="<?=$_xsOptions['Buttons']?>" />
									<p>Customizing Buttons. http://xstandard.com/en/documentation/xstandard-dev-guide/toolbar/buttons/</p>
								</li>
								<li>
									<label for="ClassImageFloatLeft"><?=__("Images will be floated by assigning a class. Look into your CSS file to find out that name.","xs")?></label>
									<input id="ClassImageFloatLeft" name="ClassImageFloatLeft" type="text" maxlength="" value="<?=$_xsOptions['ClassImageFloatLeft']?>" />
								</li>
								<li>
									<label for="ClassImageFloatRight"><?=__("Images will be floated by assigning a class. Look into your CSS file to find out that name.","xs")?></label>
									<input id="ClassImageFloatRight" name="ClassImageFloatRight" type="text" maxlength="" value="<?=$_xsOptions['ClassImageFloatRight']?>" />
								</li>
								<li>
									<label for="CSS"><?=__("CSS","xs")?></label>
									<input id="CSS" name="CSS" type="text" maxlength="" value="<?=$_xsOptions['CSS']?>" />
								</li>
								<li>
									<label for="CustomInlineElements"><?=__("CustomInlineElements","xs")?></label>
									<input id="CustomInlineElements" name="CustomInlineElements" type="text" maxlength="" value="<?=$_xsOptions['CustomInlineElements']?>" />
								</li>
								<li>
									<label for="CustomBlockElements"><?=__("CustomBlockElements","xs")?></label>
									<input id="CustomBlockElements" name="CustomBlockElements" type="text" maxlength="" value="<?=$_xsOptions['CustomBlockElements']?>" />
								</li>
								<li>
									<label for="CustomEmptyElements"><?=__("CustomEmptyElements","xs")?></label>
									<input id="CustomEmptyElements" name="CustomEmptyElements" type="text" maxlength="" value="<?=$_xsOptions['CustomEmptyElements']?>" />
								</li>
								<li>
									<label for="Debug"><?=__("Debug mode","xs")?></label>
									<?php
									$yes_selected = $no_selected = '';
									if ($_xsOptions['Debug'] === "yes") { $yes_selected = ' selected="selected"'; } else { $no_selected = ' selected="selected"'; } ?> 
									<select id="Debug" name="Debug">
										<option value="yes"<?=$yes_selected?>>enable</option>
										<option value="no"<?=$no_selected?>>disable</option>
									</select>
									<p><?=__('If debug mode is enabled, XStandard collects all kind of information about itself at runtime. <!-- You can access the information it collects on the Debugging tab of this page (TODO) --> You can see what\'s going on if you right click in the editor and choose "Editor" -> "About". You will find a register there named "Debug" which displays that information. In case the plugin shouldn\'t work as expected, you can use this feature is useful to document and submit details on your problem.','xs')?></p>
								</li>
								<li>
									<label for="EditorCSS"><?=__("EditorCSS","xs")?></label>
									<input id="EditorCSS" name="EditorCSS" type="text" maxlength="" value="<?=$_xsOptions['EditorCSS']?>" />
								</li>
								<li>
									<label for="EnableCache"><?=__("EnableCache","xs")?></label>
									<input id="EditEnableCacheorCSS" name="EnableCache" type="text" maxlength="" value="<?=$_xsOptions['EnableCache']?>" />
								</li>
								<li>
									<label for="EnableTimestamp"><?=__("EnableTimestamp","xs")?></label>
									<input id="EnableTimestamp" name="EnableTimestamp" type="text" maxlength="" value="<?=$_xsOptions['EnableTimestamp']?>" />
								</li>
								<li>
									<label for="EnablePasteMarkup"><?=__("EnablePasteMarkup","xs")?></label>
									<input id="EnablePasteMarkup" name="EnablePasteMarkup" type="text" maxlength="" value="<?=$_xsOptions['EnablePasteMarkup']?>" />
								</li>
								<li>
									<label for="EscapeUnicode"><?=__("EscapeUnicode","xs")?></label>
									<input id="EscapeUnicode" name="EscapeUnicode" type="text" maxlength="" value="<?=$_xsOptions['EscapeUnicode']?>" />
								</li>
								<li>
									<label for="ExpandWidth"><?=__("ExpandWidth","xs")?></label>
									<input id="ExpandWidth" name="ExpandWidth" type="text" maxlength="" value="<?=$_xsOptions['ExpandWidth']?>" />
								</li>
								<li>
									<label for="ExpandHeight"><?=__("ExpandHeight","xs")?></label>
									<input id="ExpandHeight" name="ExpandHeight" type="text" maxlength="" value="<?=$_xsOptions['ExpandHeight']?>" />
								</li>
								<li>
									<label for="ExpandToolbarWysiwyg"><?=__("ExpandToolbarWysiwyg","xs")?></label>
									<input id="ExpandToolbarWysiwyg" name="ExpandToolbarWysiwyg" type="text" maxlength="" value="<?=$_xsOptions['ExpandToolbarWysiwyg']?>" />
								</li>
								<li>
									<label for="ExpandToolbarSource"><?=__("ExpandToolbarSource","xs")?></label>
									<input id="ExpandToolbarSource" name="ExpandToolbarSource" type="text" maxlength="" value="<?=$_xsOptions['ExpandToolbarSource']?>" />
								</li>
								<li>
									<label for="ExpandToolbarPreview"><?=__("ExpandToolbarPreview","xs")?></label>
									<input id="ExpandToolbarPreview" name="ExpandToolbarPreview" type="text" maxlength="" value="<?=$_xsOptions['ExpandToolbarPreview']?>" />
								</li>
								<li>
									<label for="ExpandToolbarScreenReader"><?=__("ExpandToolbarScreenReader","xs")?></label>
									<input id="ExpandToolbarScreenReader" name="ExpandToolbarScreenReader" type="text" maxlength="" value="<?=$_xsOptions['ExpandToolbarScreenReader']?>" />
								</li>
								<li>
									<label for="ExpandShowStyles"><?=__("ExpandShowStyles","xs")?></label>
									<input id="ExpandShowStyles" name="ExpandShowStyles" type="text" maxlength="" value="<?=$_xsOptions['ExpandShowStyles']?>" />
								</li>
								<li>
									<label for="ExpandShowToolbar"><?=__("ExpandShowToolbar","xs")?></label>
									<input id="ExpandShowToolbar" name="ExpandShowToolbar" type="text" maxlength="" value="<?=$_xsOptions['ExpandShowToolbar']?>" />
								</li>
								<li>
									<h4>Heartbeat</h4>
									<label for="HeartbeatURL"><?=__("HeartbeatURL","xs")?></label>
									<input id="HeartbeatURL" name="HeartbeatURL" type="text" maxlength="" value="<?=$_xsOptions['HeartbeatURL']?>" />
								</li>
								<li>
									<label for="HeartbeatInterval"><?=__("HeartbeatInterval","xs")?></label>
									<input id="HeartbeatInterval" name="HeartbeatInterval" type="text" maxlength="" value="<?=$_xsOptions['HeartbeatInterval']?>" />
								</li>
								<li>
									<label for="Icons"><?=__("Icons","xs")?></label>
									<input id="Icons" name="Icons" type="text" maxlength="" value="<?=$_xsOptions['Icons']?>" />
								</li>
								<li>
									<label for="IndentOutput"><?=__("IndentOutput","xs")?></label>
									<input id="IndentOutput" name="IndentOutput" type="text" maxlength="" value="<?=$_xsOptions['IndentOutput']?>" />
								</li>
								<li>
									<label for="Lang"><?=__("Lang","xs")?></label>
									<input id="Lang" name="Lang" type="text" maxlength="" value="<?=$_xsOptions['Lang']?>" />
								</li>
								<li>
									<label for="LatestVersion"><?=__("LatestVersion","xs")?></label>
									<input id="LatestVersion" name="LatestVersion" type="text" maxlength="" value="<?=$_xsOptions['LatestVersion']?>" />
								</li>
								<li>
									<label for="License"><?=__("License","xs")?></label>
									<input id="License" name="License" type="text" maxlength="" value="<?=$_xsOptions['License']?>" />
								</li>
								<li>
									<label for="Localization"><?=__("Localization","xs")?></label>
									<input id="Localization" name="Localization" type="text" maxlength="" value="<?=$_xsOptions['Localization']?>" />
								</li>
								<li>
									<label for="Mode"><?=__("Mode","xs")?></label>
									<input id="Mode" name="Mode" type="text" maxlength="" value="<?=$_xsOptions['Mode']?>" />
								</li>
								<li>
									<label for="Namespaces"><?=__("Namespaces","xs")?></label>
									<input id="Namespaces" name="Namespaces" type="text" maxlength="" value="<?=$_xsOptions['Namespaces']?>" />
								</li>
								<?php
								// reverse numeric option val to associated array
					
								$this->main->assoc_keys = self::$bitmaskOptions;
								print "<pre>"; print_r($_xsOptions['Options']); print "</pre>";
								$this->main->reverse_mask($_xsOptions['Options']);
								print_r($this->main->assoc_keys);
								$i = 0;
								foreach($this->main->assoc_get(true) as $optionname => $optionval) { 
									if ($optionval === "1") { $checked = ' checked="checked"'; } else { $checked = ''; }
									if ($optionname === "NIY") { 
										/* not implemented yet - so do nothing */
									} else { ?>
									<li>
										<label for="<?=$optionname?>"><?php print self::$bitmaskOptionDescs[$i]; ?></label>
										<input id="<?=$optionname?>" name="<?=$optionname?>" type="checkbox" <?=$checked?> />
									</li>
								<?php 
									}
									$i++;
								} ?>
								<li>
									<label for="Placeholders"><?=__("Placeholders","xs")?></label>
									<input id="Placeholders" name="Placeholders" type="text" maxlength="" value="<?=$_xsOptions['Placeholders']?>" />
								</li>
																<li>
									<label for="PreviewXSLT"><?=__("PreviewXSLT","xs")?></label>
									<input id="PreviewXSLT" name="PreviewXSLT" type="text" maxlength="" value="<?=$_xsOptions['PreviewXSLT']?>" />
								</li>
																<li>
									<label for="Rel"><?=__("Rel","xs")?></label>
									<input id="Rel" name="Rel" type="text" maxlength="" value="<?=$_xsOptions['Rel']?>" />
								</li>
								<li>
									<label for="Rev"><?=__("Rev","xs")?></label>
									<input id="Rev" name="Rev" type="text" maxlength="" value="<?=$_xsOptions['Rev']?>" />
								</li>
								<li>
									<label for="ScreenReaderXSLT"><?=__("ScreenReaderXSLT","xs")?></label>
									<input id="ScreenReaderXSLT" name="ScreenReaderXSLT" type="text" maxlength="" value="<?=$_xsOptions['ScreenReaderXSLT']?>" />
								</li>
								<li>
									<label for="Styles"><?=__("Styles","xs")?></label>
									<input id="Styles" name="Styles" type="text" maxlength="" value="<?=$_xsOptions['Styles']?>" />
								</li>
								<li>
									<label for="ShowStyles"><?=__("ShowStyles","xs")?></label>
									<input id="ShowStyles" name="ShowStyles" type="text" maxlength="" value="<?=$_xsOptions['ShowStyles']?>" />
								</li>
								<li>
									<label for="ShowToolbar"><?=__("ShowToolbar","xs")?></label>
									<input id="ShowToolbar" name="ShowToolbar" type="text" maxlength="" value="<?=$_xsOptions['ShowToolbar']?>" />
								</li>
								<li>
									<label for="Toolbar"><?=__("Toolbar","xs")?></label>
									<input id="Toolbar" name="Toolbar" type="text" maxlength="" value="<?=$_xsOptions['Toolbar']?>" />
								</li>
								<li>
									<label for="ToolbarWysiwyg"><?=__("ToolbarWysiwyg","xs")?></label>
									<input id="ToolbarWysiwyg" name="ToolbarWysiwyg" type="text" maxlength="" value="<?=$_xsOptions['ToolbarWysiwyg']?>" />
								</li>
								<li>
									<label for="ToolbarSource"><?=__("ToolbarSource","xs")?></label>
									<input id="ToolbarSource" name="ToolbarSource" type="text" maxlength="" value="<?=$_xsOptions['ToolbarSource']?>" />
								</li>
								<li>
									<label for="ToolbarPreview"><?=__("ToolbarPreview","xs")?></label>
									<input id="ToolbarPreview" name="ToolbarPreview" type="text" maxlength="" value="<?=$_xsOptions['ToolbarPreview']?>" />
								</li>
								<li>
									<label for="ToolbarScreenReader"><?=__("ToolbarScreenReader","xs")?></label>
									<input id="ToolbarScreenReader" name="ToolbarScreenReader" type="text" maxlength="" value="<?=$_xsOptions['ToolbarScreenReader']?>" />
								</li>
								<li>
									<label for="ToolbarEffect"><?=__("ToolbarEffect","xs")?></label>
									<select id="ToolbarEffect" name="ToolbarEffect" value="<?=$_xsOptions['ToolbarEffect']?>" />
									<?php $effectVals = array('','linear-gradient');
									foreach ($effectVals as $effect) { 
										if ($_xsOptions['ToolbarEffect'] === $effect) { $selected=' selected="selected"'; } else { $selected = ''; }
										?>
										<option value=""<?php print $selected?>><?php if ('' === $effect) { print "none"; } else { print $effect; } ?></option>
									<?php } ?>
									</select>
								</li>
								<!-- Actually the libraries are internal stuff. Why bother plugin users with it? Anyone using it's own script?  -->
<!--
								<li>
									<label for="ImageLibraryURL"><?=__("ImageLibraryURL","xs")?></label>
									<input id="ImageLibraryURL" name="ImageLibraryURL" type="text" maxlength="" value="<?=$_xsOptions['ImageLibraryURL']?>" />
								</li>
								<li>
									<label for="AttachmentLibraryURL"><?=__("AttachmentLibraryURL","xs")?></label>
									<input id="AttachmentLibraryURL" name="AttachmentLibraryURL" type="text" maxlength="" value="<?=$_xsOptions['AttachmentLibraryURL']?>" />
								</li>
								<li>
									<label for="SpellCheckerURL"><?=__("SpellCheckerURL","xs")?></label>
									<input id="SpellCheckerURL" name="SpellCheckerURL" type="text" maxlength="" value="<?=$_xsOptions['SpellCheckerURL']?>" />
								</li>
								<li>
-->
									<label for="SpellCheckerLangFilter"><?=__("SpellCheckerLangFilter","xs")?></label>
									<input id="SpellCheckerLangFilter" name="SpellCheckerLangFilter" type="text" maxlength="" value="<?=$_xsOptions['SpellCheckerLangFilter']?>" />
								</li>
								<li>
									<label for="SpellCheckerLang"><?=__("SpellCheckerLang","xs")?></label>
									<input id="SpellCheckerLang" name="SpellCheckerLang" type="text" maxlength="" value="<?=$_xsOptions['SpellCheckerLang']?>" />
								</li>
								<li>
									<label for="DirectoryURL"><?=__("DirectoryURL","xs")?></label>
									<input id="DirectoryURL" name="DirectoryURL" type="text" maxlength="" value="<?=$_xsOptions['DirectoryURL']?>" />
								</li>
								<li>
									<label for="SubdocumentURL"><?=__("SubdocumentURL","xs")?></label>
									<input id="SubdocumentURL" name="SubdocumentURL" type="text" maxlength="" value="<?=$_xsOptions['SubdocumentURL']?>" />
								</li>
								<li>
									<label for="ProxySetting"><?=__("ProxySetting","xs")?></label>
									<input id="ProxySetting" name="ProxySetting" type="text" maxlength="" value="<?=$_xsOptions['ProxySetting']?>" />
								</li>								<li>
									<label for="ProxyServer"><?=__("ProxyServer","xs")?></label>
									<input id="ProxyServer" name="ProxyServer" type="text" maxlength="" value="<?=$_xsOptions['ProxyServer']?>" />
								</li>								<li>
									<label for="ProxyPort"><?=__("ProxyPort","xs")?></label>
									<input id="ProxyPort" name="ProxyPort" type="text" maxlength="" value="<?=$_xsOptions['ProxyPort']?>" />
								</li>								<li>
									<label for="ProxyUser"><?=__("ProxyUser","xs")?></label>
									<input id="ProxyUser" name="ProxyUser" type="text" maxlength="" value="<?=$_xsOptions['ProxyUser']?>" />
								</li>
								
							</ol>
							<input type="hidden" name="update_xsSettings" value="bla" />
							<input class="button-primary" type="submit" name="update_xstandardSettings" value="<?=__("Save XStandard Configuration","xs")?>" />
							<input class="button" type="submit" name="restore_xstandardSettings" value="<?=__("Restore Defaults","xs")?>" />
						</form>

						<!-- DISPLAY THINGS FOR DEBUGGING -->
						<pre>XS_EXECUTING_OS:<?=XS_EXECUTING_OS?><br />
						XS_SYSTEM_SEPARATOR:<?=XS_SYSTEM_SEPARATOR?><br />
						XS_PLUGINDIR_NAME:<?=XS_PLUGINDIR_NAME?><br />
						XS_FULLPATH:<?=XS_FULLPATH?><br />
						XS_URL:<?=XS_URL?><br />
						XS_UPLOADPATH:<?=XS_UPLOADPATH?><br />
						XS_WPURL:<?=XS_WPURL?><br />
						XS_LANG:<?=XS_LANG?><br />
						Plugin Version: <?=$this->pluginVersion?><br />
						required WordPress Version: <?=$this->requiredWordPressVersion?><br />
						highest tested WordPress Version: <?=$this->highestTestedWordPressVersion?><br />
						XStandard Version included in this Plugin: <?=$this->xstandardVersionIncluded?><br />
						XStandard Version online: <?=$this->xstandardLatest?></pre>

<br/>
getAdminOptions()
<pre><?php $options = $this->getAdminOptions();
	print_r($options);
?></pre>

getXStandardOptions()
<pre><?php $options = $this->getXStandardOptions();
	print_r($options);
?></pre>
				</div><!-- end wrap div -->
<?php		} // end of option page
		} // end of class
	} // endif;


	if (class_exists("XStandard")) {
		
		$xs = new XStandard(); // instantiate XStandard 
	}

	//Initialize the admin panel
	if (!function_exists("XStandardAdminPanel")) {
		function XStandardAdminPanel() {
			global $xs;
			if (!isset($xs)) {
				return;
			}
			if (function_exists('add_options_page')) {
				add_options_page('XStandard', 'XStandard', 9, basename(__FILE__), array(&$xs, 'xsOptionsPage'));
			}
		}
	}

	//Actions and Filters
	if (isset($xs)) {
		//Actions
		add_action('admin_menu', 'XStandardAdminPanel');
		// add_action('wp_head', array(&$dl_pluginSeries, 'addHeaderCode'), 1);
		add_action(__FILE__, array(&$xs, 'init'));
		//Filters
		add_filter('edit_form_advanced', array(&$xs, '_filter_edit_form_advanced'));
		add_filter('edit_page_form', array(&$xs, '_filter_edit_form_advanced'));
		add_filter('admin_footer', array(&$xs, '_filter_js_admin_head'));
		//remove_filter('the_excerpt', 'wpautop');  
		//remove_filter('the_excerpt', 'wptexturize');
		remove_filter('the_content', 'wpautop');
		remove_filter('the_content', 'wptexturize');
	}
?>